package com.lemon.smartsafetynew.ui.adapter.incident;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafetynew.entity.incident.IncidentSafePatrolChildItemVo;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolMediaVo;
import com.lemon.smartsafetynew.ui.activity.incident.IncidentSafePatrolProcessActivity;
import com.lemon.smartsafetynew.ui.adapter.patrol.PatrolAttachmentAdapter;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/9/6.
 */

public class IncidentSafePatrolCheckItemAdapter extends LemonRcvAdapter<IncidentSafePatrolChildItemVo> {

    public IncidentSafePatrolCheckItemAdapter(@Nullable List<IncidentSafePatrolChildItemVo> data) {
        super(data);
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<IncidentSafePatrolChildItemVo> {

        @Bind(R.id.incident_child_item_tv)
        TextView incidentChildItemTv;
        @Bind(R.id.incident_check_result_tv)
        TextView incidentCheckResultTv;
        @Bind(R.id.incident_check_item_remark_tv)
        TextView incidentCheckItemRemarkTv;
        @Bind(R.id.recyclerView)
        RecyclerView recyclerView;

        private IncidentAttachmentAdapter mMediaAdapter;

        @Override
        public int getLayoutResId() {
            return R.layout.item_incident_child_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {

        }

        @Override
        public void handleData(IncidentSafePatrolChildItemVo incidentSafePatrolChildItemVo, int position) {

            //TODO
            incidentChildItemTv.setText(CommonUtil.avoidNullString(incidentSafePatrolChildItemVo.getFlow_name()));
            incidentCheckResultTv.setText(CommonUtil.avoidNullString(incidentSafePatrolChildItemVo.getConclusion_name()));
            //incidentCheckItemRemarkTv.setText(CommonUtil.avoidNullString(incidentSafePatrolChildItemVo.getRemark()));

            List<SafePatrolMediaVo> mediaVos = incidentSafePatrolChildItemVo.getAttests();

            if (mediaVos != null && mediaVos.size() != 0) {
                incidentCheckItemRemarkTv.setText(CommonUtil.avoidNullString(mediaVos.get(0).getData_remark()));
            } else {
                incidentCheckItemRemarkTv.setText(CommonUtil.avoidNullString(incidentSafePatrolChildItemVo.getRemark()));
            }

            GridLayoutManager gridLayoutManager = new GridLayoutManager(recyclerView.getContext(), 3);
            recyclerView.setVisibility(View.VISIBLE);
            recyclerView.setLayoutManager(gridLayoutManager);
            recyclerView.setNestedScrollingEnabled(false);
            mMediaAdapter = new IncidentAttachmentAdapter(incidentSafePatrolChildItemVo.getAttests(), IncidentSafePatrolProcessActivity.class.getName());
            recyclerView.setAdapter(mMediaAdapter);

        }
    }
}
